﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Synchronization;
using Obra.Common;

namespace Obra.Sync
{
    /// <summary>
    /// Synchronization service is a source and target of synchronization.
    /// </summary>
    /// <remarks>
    /// <para>
    /// A synchronization service provides the following facilities.
    ///   1. Enumerate media files local to the synchronization service provider.
    ///   2. Save a media file from an external provider to this provider.
    ///   3. Load a media file from this provider to be saved to an external provider.
    /// </para>
    /// </remarks>
    public interface ISyncService
    {
        /// <summary>
        /// The name of this synchronization service.
        /// </summary>
        string Name
        {
            get;
        }

        /// <summary>
        /// The description of this synchronization service.
        /// </summary>
        string Description
        {
            get;
        }

        /// <summary>
        /// This method is called before any sync action occurs.
        /// </summary>
        void Connect();

        /// <summary>
        /// The method is called after synchronization has concluded.
        /// </summary>
        void Disconnect();

        /// <summary>
        /// The options for this sync service.
        /// </summary>
        SyncOptions SyncOptions
        {
            get;
        }

        /// <summary>
        /// Checksum a media file.
        /// </summary>
        /// <param name="mediaItemMetadata">
        /// Metadata of the media file to compute the checksum of.
        /// </param>
        /// <returns>
        /// String representation of the media file's checksum.
        /// </returns>
        /// <remarks>
        /// <para>
        /// The checksum is computed lazily because it is expected that the 
        /// user will have many GBs worth of media files.  The checksum is only
        /// computed when it is initially added to the metadata store, and when
        /// a media file is updated.
        /// </para>
        /// </remarks>
        string ComputeChecksum(
            MediaItemMetadata mediaItemMetadata);

        /// <summary>
        /// Delete a media file from this provider.
        /// </summary>
        /// <param name="mediaItemMetadata">
        /// Metadata for the media file to delete.
        /// </param>
        void DeleteMediaFile(
            MediaItemMetadata mediaItemMetadata);

        /// <summary>
        /// Enumerate the media files on this provider.
        /// </summary>
        /// <returns>
        /// List of media metadata for media files on this provider.
        /// </returns>
        List<MediaItemMetadata> EnumerateMediaFiles();

        /// <summary>
        /// Save a media file to this provider.
        /// </summary>
        /// <param name="syncItemTransfer">
        /// SyncItem to save.
        /// </param>
        void SaveChange(
            ISyncItemTransfer syncItemTransfer);

        /// <summary>
        /// Load a media file from this provider.
        /// </summary>
        /// <param name="mediaFileName">
        /// Name of the media file to load.
        /// </param>
        /// <returns>
        /// Class wrapping the transfer object.
        /// </returns>
        ISyncItemTransfer LoadChange(
            string mediaFileName);
    }
}
